<!---
	Copyright 2010 Edward Trudeau, Jeremy Battle
    This software is freely available under the MIT License: http://www.opensource.org/licenses/mit-license.php
    http://ayc.googlecode.com
    
--->

<cfcomponent>
	<cffunction name="getGrid" access="remote" returntype="any" returnformat="JSON">
		<cfargument name="page" required="true">
		<cfargument name="pagesize" required="true">
		<cfargument name="gridsortcolumn" required="true">
		<cfargument name="gridsortdirection" required="true" default="asc">
		<cfargument name="objectName" required="true">
		<cfargument name="parentObject" required="true">	
		
		<cfset var sortColumn = "" />
		<cfset var sort = "" />
		<cfset var parentObject = listGetAt(arguments.parentObject,1,"|") />
		<cfset var parentId = listGetAt(arguments.parentObject,2,"|") />
		
		<cfif NOT len(trim(arguments.gridsortcolumn))>
			<cfset sortColumn = "#arguments.objectName#id">
		<cfelse>
			<cfset sortColumn = arguments.gridsortcolumn>
		</cfif>

		<cfset sort = arguments.gridsortdirection />
		
		<cfset currentObject = EntityLoad("#arguments.ObjectName#",{"#parentObject#id" = "#parentId#"},"#sortColumn #sort#")>
		
		<cfset objectToQuery = entityToQuery(currentObject)>
		
		<cfreturn queryconvertforgrid(objectToQuery,arguments.page,arguments.pagesize) />
</cfcomponent>

